//
//  AlarmListCell.m
//  efairy
//
//  Created by 李锋 on 2019/2/25.
//  Copyright © 2019年 East. All rights reserved.
//

#import "AlarmListCell.h"
#import "DeviceListCell.h"


@implementation AlarmListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initView];
    }
    return self;
}

-(void)initView{
    
    UIView *topLine = [[UIView alloc]init];//线条
    topLine.backgroundColor  = ColorFromRGB(0xeff0f4);
    
    _checkbox = [[UIImageView alloc]init];
    _checkedImage = [UIImage imageNamed:@"icon_checked"];//未选中
    _unCheckedImage = [UIImage imageNamed:@"icon_no_checked"];//选中
    _checkbox.image = _unCheckedImage;
    
    _itemView = [[UIView alloc]init];
    _itemView.backgroundColor = [UIColor whiteColor];
    
 
    //通道类型和通道号
    _pTypeName = [[UILabel alloc]init];
    _pTypeName.font = [UIFont boldSystemFontOfSize:16.f];//字体加粗
    _pTypeName.textColor = ColorFromRGB(0x333333);

    //报警类型
    _alarmType = [[UILabel alloc]init];
    _alarmType.font = [UIFont systemFontOfSize:14.f];
    _alarmType.textColor = ColorFromRGB(0x333333);
    _alarmType.textAlignment = NSTextAlignmentRight;
    //报警值title
    _alarmHighestValueLaebl = [[UILabel alloc]init];
    _alarmHighestValueLaebl.font = [UIFont systemFontOfSize:14.f];
    _alarmHighestValueLaebl.textColor = ColorFromRGB(0x333333);
    _alarmHighestValueLaebl.text = @"报警值/阈值";
    //报警值
    _alarmHighestValue = [[UILabel alloc]init];
    _alarmHighestValue.font = [UIFont systemFontOfSize:14.f];
    _alarmHighestValue.textColor = ColorFromRGB(0x999999);
    _alarmHighestValue.textAlignment = NSTextAlignmentRight;
   
    //报警之间title
    _alarmtTimeLaebl = [[UILabel alloc]init];
    _alarmtTimeLaebl.font = [UIFont systemFontOfSize:14.f];
    _alarmtTimeLaebl.textColor = ColorFromRGB(0x333333);
    _alarmtTimeLaebl.text = @"报警时间";
    //报警之间
    _alarmtTime = [[UILabel alloc]init];
    _alarmtTime.font = [UIFont systemFontOfSize:14.f];
    _alarmtTime.textColor = ColorFromRGB(0x999999);
    _alarmtTime.textAlignment = NSTextAlignmentRight;
    
    [self.contentView sd_addSubviews:@[topLine,_itemView,_checkbox]];
   
    topLine.sd_layout.widthIs(SCREEN_WIDTH).heightIs(8)
    .topSpaceToView(self.contentView, 0);
    
    _checkbox.sd_layout.widthIs(12).heightIs(12)
    .leftSpaceToView(self.contentView, 18)
    .topSpaceToView(self.contentView,48);
    
    _itemView.sd_layout.widthIs(SCREEN_WIDTH * 0.85).heightIs(100)
    .rightSpaceToView(self.contentView, 8)
    .topSpaceToView(topLine, 0);
    
     [_itemView sd_addSubviews:@[_pTypeName,_alarmType,_alarmHighestValueLaebl,_alarmHighestValue,_alarmtTimeLaebl,_alarmtTime]];
    _pTypeName.sd_layout.heightIs(16)
    .leftSpaceToView(_itemView, 12)
    .rightSpaceToView(_itemView, 60)
    .topSpaceToView(_itemView,16);
    
    _alarmType.sd_layout.widthIs(50).heightIs(12)
    .rightSpaceToView(_itemView, 12)
    .topSpaceToView(_itemView,18);
    
    
    _alarmHighestValueLaebl.sd_layout.heightIs(14)
    .leftSpaceToView(_itemView, 12)
    .rightSpaceToView(_itemView, 144)
    .topSpaceToView(_pTypeName,12);
    
    _alarmHighestValue.sd_layout.widthIs(131).heightIs(14)
    .rightSpaceToView(_itemView, 12)
    .topSpaceToView(_pTypeName,14);
    
    _alarmtTimeLaebl.sd_layout.heightIs(14)
    .leftSpaceToView(_itemView, 12)
    .rightSpaceToView(_itemView, 159)
    .topSpaceToView(_alarmHighestValueLaebl,12);
    
    _alarmtTime.sd_layout.widthIs(159).heightIs(14)
    .rightSpaceToView(_itemView, 12)
    .topSpaceToView(_alarmHighestValueLaebl,12);
    
    self.contentView.backgroundColor =ColorFromRGB(0xeff0f4);
    [self setupAutoHeightWithBottomView:_itemView bottomMargin:0];
}


-(void)setModeDatas:(AlarmNoDispostListModel *)data{
    if(data.isChecked){
        _checkbox.image = _checkedImage;
    }else{
         _checkbox.image = _unCheckedImage;
    }
    _pTypeName.text = data.efairydevicealarmstatistics_c_name;//通道名和通道号
    _alarmType.textColor = ColorFromRGB([DeviceListCell getDeviceStateColor:(int)data.efairydevicealarmstatistics_alarm_type]);
    _alarmType.text = [DeviceListCell getDeviceState:((int)data.efairydevicealarmstatistics_alarm_type)];//报警类型
    _alarmHighestValue.text = data.efairydevicealarmstatistics_highest_value;//报警值/阈值
    _alarmtTime.text = data.efairydevicealarmstatistics_start_time;//报警之间
}

@end
